package com.example.demo.mapper;

import com.example.demo.entity.Idea;
import com.example.demo.entity.Open;
import com.example.demo.entity.Status;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface StatusMapper {

    //用户点赞的说说
    @Select("SELECT * FROM status where openid=#{openid}")
    @Results({
            @Result(column = "openid",property = "openid"),
            @Result(column = "ideaid",property = "ideaid"),
            @Result(column = "status",property = "status"),
            @Result(
                    property = "open",
                    javaType = Open.class,
                    column = "openid",
                    one=@One(select ="com.example.demo.mapper.OpenMapper.findOpenid")
            ),
            @Result(
                    property = "idea",
                    javaType = Idea.class,
                    column = "ideaid",
                    one = @One(select = "com.example.demo.mapper.IdeaMapper.findideaone")
            )
    })
    public List<Status> selectAll(String openid);

    //根据ideaid和openid搜索该说说是否被点赞
    @Select("select * from status where ideaid=#{ideaid} and openid=#{openid}")
    public List<Status> findByIdeaidAndOpenid(int ideaid,String openid);

    @Insert("insert into status(openid,ideaid,status)" +
            "value(#{openid},#{ideaid},#{status})")
    public int InsetsStatus(Status status);

    //取消点赞删除数据
    @Delete("delete from status where ideaid=#{ideaid} and openid=#{openid}")
    public int deleteStatus(int ideaid,String openid);

}
